const App = getApp();
const wxParse = require('../../wxParse/wxParse.js')
const qingxilist = require('../../utils/qingxilist.js')
const siteinfo = require('../../siteinfo.js')

Page({

  data: {
    // 页面参数
    qingxilist: qingxilist,
    options: {},
    ChengZhongCunId:'',
    // 页面元素
    scrollTop: 0,
    index: 0,
    detail: {},
    IsGongshui: '',
    diquzongshu:'',//低区室外水表总数：
    diquchangdu:'',//低区立管总长度
    gaoquzongshu:0,//估算高区水表总数
    gaoquchangdu:0,//估算高区立管总长度
    hubiaozongshu:'',//户表总数
    LouDongHuShu:'',//楼栋户数
    liguanchangdu:'',//立管总长度
    dayu:'',//楼层层数是否大于最高立管楼层
    disableQingXiFangShi:true,
    changbian: '',
    kuanbian: '',
    ZiXi: '',
    mianji:'',
    GuanCai: [],
    louceng:'',// 楼层
    GuanCaiChangDu: [],
    ChaoBiaoDaoHu: '',
    DongBiaoWeiZhi: [],// 栋表位置
    DongBiaoShiNei: [],// 栋表室内
    DongBiaoShiWai: [],// 栋表室外
    HuBiaoWeiZhi: [],// 
    HuBiaoGeShu: [],// 
    ShuiChiYong: [],
    ShuiChiZhong: [],
    ShuiChiZhongGeShu: [],
    tuResult: true, //检测一下是不是有没有图片未传完
    XianChangZhaoPian: [],
    GongZuoZhaoPian: [],
    GongShuiFangShi:[],
    QingXiFangShi:[],
    WenTiZhaoPian: [],
    qingkong: '',
    TianBiaoRiQi: '',
    $data: {},
    qingkongList: [], //搜索的机构的list
    liguanList:[{
      genshu:'',
      zuigao:'',
      zuidi:''
    }],
    isShifouList: [{
      value: '是'
    },
    {
      value: '否'
    },
    ],
    ChaoBiaoDaoList: [
      {
        value: '抄表未到栋/户'
      },
      {
        value: '抄表到栋/户'
      },
      {
        value: '抄表到栋'
      },
      {
        value: '抄表到户'
      }
    ],
    LouCengGaoDuList: [
      {
        value: '7层及以下',
        checked: false
      },
      {
        value: '8~15层',
        checked: false
      },
      {
        value: '16层及以上',
        checked: false
      }
    ],
    GuanCaiList: [
      {
        value: '灰口铸铁管',
        dataname: 'huikouchangdu',
        checked: false
      },
      {
        value: '球墨铸铁管',
        dataname: 'qiumochangdu',
        checked: false
      },
      {
        value: '镀锌钢管',
        dataname: 'duxinchangdu',
        checked: false
      },
      {
        value: '钢塑管',
        dataname: 'suogangguan',
        checked: false
      },
      {
        value: '铝塑管',
        dataname: 'lvsuochangdu',
        checked: false
      },
      {
        value: 'PVC管',
        dataname: 'pvcchangdu',
        checked: false
      },
      {
        value: 'PPR',
        dataname: 'pprchangdu',
        checked: false
      },
      {
        value: 'PE管',
        dataname: 'pechangdu',
        checked: false
      },
      {
        value: '薄壁不锈钢钢管316',
        dataname: '316changdu',
        checked: false
      },
      {
        value: '薄壁不锈钢钢管304',
        dataname: '304changdu',
        checked: false
      },
      {
        value: '内衬不锈钢',
        dataname: 'neichenchangdu',
        checked: false
      },
      {
        value: '聚四氟乙烯管',
        dataname: 'jusichangdu',
        checked: false
      },
      {
        value: '其他',
        dataname: 'guancaiqitachangdu',
        checked: false
      }
    ],
    DongBiaoWeiZhiList: [
      {
        value: "室外",
        checked: false,
        child: [
          {
            value: "地面",
            checked: false
          },
          {
            value: "水表井",
            checked: false
          },
          {
            value: "楼顶",
            checked: false
          },
          {
            value: "其他",
            checked: false
          }
        ]
      },
      {
        value: "室内",
        checked: false,
        child: [
          {
            value: "地下",
            checked: false
          },
          {
            value: "一楼",
            checked: false
          },
          {
            value: "楼顶",
            checked: false
          },
          {
            value: "其他",
            checked: false
          }
        ]
      }
    ],
    HuBiaoWeiZhiList: [
      {
        value: '户内',
        dataname: 'huneigeshu',
        checked: false
      },
      {
        value: '管道井',
        dataname: 'guandaojinggeshu',
        checked: false
      },
      {
        value: '楼梯间',
        dataname: 'loutijiangeshu',
        checked: false
      },
      {
        value: '楼顶',
        dataname: 'loudinggeshu',
        checked: false
      },
      {
        value: '一楼室内',
        dataname: 'yiloushineigeshu',
        checked: false
      },
      {
        value: '一楼室外',
        dataname: 'yiloushiwaigeshu',
        checked: false
      },
      {
        value: '其他',
        dataname: 'hubiaoqitageshu',
        checked: false
      }
    ],
    ShuiChiZhuangTai: [
      {
        value: '弃用',
        dataname: 'ShuiChiQiYongShuLiang',
        checked: false
      },
      {
        value: '在用',
        dataname: 'ShuiChiYongShuLiang',
        checked: false
      }
    ],
    YongShuiChi: [
      {
        value: '单独生活',
        dataname: 'shenghuogeshu',
        datavalue:'',
        checked: false
      },
      {
        value: '单独消防',
        dataname: 'xiaofanggeshu',
        datavalue:'',
        checked: false
      },
      {
        value: '生活消防共用',
        dataname: 'zonggong',
        datavalue:'',
        checked: false
      },
      {
        value: '天面',
        dataname: 'tianmiangeshu',
        datavalue:'',
        checked: false
      },
      {
        value: '地下',
        dataname: 'dixiageshu',
        datavalue:'',
        checked: false
      }
    ],
    GongShuiFangShiList: [
      {
        value: '市政直供',
        checked: false
      },
      {
        value: '市政+水泵',
        checked: false
      },
      {
        value: '市政+天面池',
        checked: false
      },
      {
        value: '市政+水泵+天面池',
        checked: false
      },
      {
        value: '市政+地下水池+水泵',
        checked: false
      },
      {
        value: '市政+地下水池+水泵+天面池',
        checked: false
      },
    ],
    QingXiFangShiList: [
      {
        value: '不清洗',
        checked: false
      },
      {
        value: '业主自洗',
        checked: false
      },
      {
        value: '其他有资质单位清洗',
        checked: false
      },
      {
        value: '一年清洗2次以上',
        checked: false
      },
      {
        value: '一年清洗2次 ',
        checked: false
      },
      {
        value: '一年清洗1次',
        checked: false
      },
      {
        value: '一年以上清洗1次',
        checked: false
      },
      {
        value: '有CMA认证的水质检测报告',
        checked: false
      },
      {
        value: '有非CMA认证的水质检测报告',
        checked: false
      },
      {
        value: '无水质检测报告',
        checked: false
      }
    ],
    YouWuShuiZhi: [
      {
        value: '有',
        checked: false
      },
      {
        value: '无',
        checked: false
      }
    ],
    GuanLiRenYuanList: [
      {
        value: '专人管理',
        checked: false
      },
      {
        value: '无人管理',
        checked: false
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this
    let arr = {
      ..._this.data
    }
    delete arr.$data
    this.setData({
      $data: arr
    })
    this.setData({
      ChengZhongCunId:options.id
    })
  },

  selectAddress() {
    App.getPermission(this)
  },
  formSubmit(e) {
    console.log('提交')
    var _this = this
    let data = {
      ...e.detail.value
    }
    // console.log(2)
    try {
      // console.log(3)
      // console.log(this.data.loading)
      // if (_this.data.loading) {
      //   return
      // }
      // console.log(4)
      // _this.setData({
      //   loading: true
      // })
      data.ChengZhongCunId = getApp().globalData.ChengZhongCunId// 城中村Id
      data.LiGuanZu = JSON.stringify(this.data.liguanList)// 立管组数组
      data.TianBiaoRiQi = this.data.TianBiaoRiQi
      data.CengShuDaYuZuiGaoLiGuan = this.data.dayu
      data.GuanCai = this.data.GuanCai.join(',')
      data.GuanCaiChangDu = JSON.stringify(this.data.GuanCaiChangDu)
      data.DongBiaoWeiZhi = this.data.DongBiaoWeiZhi.join(',')
      data.DongBiaoShiNei = this.data.DongBiaoShiNei.join(',')
      data.DongBiaoShiWai = this.data.DongBiaoShiWai.join(',')
      data.HuBiaoWeiZhi = this.data.HuBiaoWeiZhi.join(',')
      data.HuBiaoGeShu = JSON.stringify(this.data.HuBiaoGeShu)
      data.ShuiChiYong = this.data.ShuiChiYong.join(',')
      data.ShuiChiZhong = this.data.ShuiChiZhong.join(',')
      data.GongShuiFangShi = this.data.GongShuiFangShi.join(',')
      data.QingXiFangShi = this.data.QingXiFangShi.join(',')
      data.ShuiChiZhongGeShu = JSON.stringify(this.data.ShuiChiZhongGeShu)
      // data.XianChangZhaoPian = this.data.XianChangZhaoPian.join(",")
      // data.GongZuoZhaoPian = this.data.GongZuoZhaoPian.join(",")
      // data.WenTiZhaoPian = this.data.WenTiZhaoPian.join(",")
    } catch (e) {
      console.log(e)
      wx.showModal({
        cancelColor: 'cancelColor',
        showCancel: false,
        title: '错误',
        content: 'e'
      })
    }
    console.log("提交数据", data)
    let b = this.validataData(data)
    if(b){
      return
    }
    console.log(33333333333333)
    wx.request({
      url: App.api_test + (e.detail.target.dataset.xingwei == "tijiao"?'SaveChengZhongCunFuBiao':'ZanCunChengZhongCunFuBiao'),
      header: {
        'content-type': 'application/JSON',
      },
      method: 'POST',
      data: {
        fuBiaoEntity:data,
        openId:wx.getStorageSync('openid'),
        userId:wx.getStorageSync('user_id')
      },
      success(res){
        _this.setData(_this.data.$data)
        wx.showModal({
          title: res.data,
          showCancel: false,
          complete: () => {
            _this.setData({
              loading: false
            })
          }
        })
      },
      fail(res) {
        console.log(res);
      }
    })
  },
  validataData(data){
    // console.log("楼栋户数"+data.LouDongHuShu)
    // console.log("户表户数"+data.HuBiaoZongShu)
    // if(Number(data.LouDongHuShu)!=Number(data.HuBiaoZongShu)){
    //   wx.showModal({
    //     title:'楼栋户数和户表数量不一致',
    //     showCancel: false
    //   })
    //   return true
    // }
    // 管材总长度计算
    let sumGuanCaiChangDuList = JSON.parse(data.GuanCaiChangDu)
    let sumGuanCaiChangDu  = 0
    sumGuanCaiChangDuList.forEach(function(item,index){
      sumGuanCaiChangDu += Number((item.value=""?0:item.value))
    })
    
    if(Number(data.LiGuanZongChangDu)!=sumGuanCaiChangDu){
      wx.showModal({
        title:'立管长度与管材总和不一致',
        showCancel: false
      })
      return true
    }

    /**
     * 水表总数校验
     */
    console.log(data.ShuiBiaoZongShu)
    let sumShuiBiao = Number(data.DongBiaoGeShu)+Number(data.HuBiaoZongShu)
    console.log(sumShuiBiao)
    if(Number(data.ShuiBiaoZongShu)!=sumShuiBiao){
      wx.showModal({
        title:'水表总数与(户表+栋表和)不一致',
        showCancel: false
      })
      return true
    }
    // 栋表总数校验
    let sumDonBiao = Number(data.DongBiaoQiYeZongShu)+Number(data.DongBiaoQiTaZongShu)
    if(Number(data.DongBiaoGeShu)!=sumDonBiao){
      wx.showModal({
        title:'栋表总数=企业+其他',
        showCancel: false
      })
      return true
    }
    // 栋表企业校验
    let sumDonBiaoQiYe = Number(data.DongBiaoQiYeZhiNengGeShu)+Number(data.DongBiaoQiYeRenGongBiaoGeShu)
    if(Number(data.DongBiaoQiYeZongShu)!=sumDonBiaoQiYe){
      wx.showModal({
        title:'请输入正确的栋表供水企业总数',
        showCancel: false
      })
      return true
    }
    // 栋表其他校验
    let sumDonBiaoQiTa = Number(data.DongBiaoQiTaZhiNengGeShu)+Number(data.DongBiaoQiTaRenGongGeShu)
    if(Number(data.DongBiaoQiTaZongShu)!=sumDonBiaoQiTa){
      wx.showModal({
        title:'请输入正确的栋表其他总数',
        showCancel: false
      })
      return true
    }
    // 户表总数校验
    let sumHuBiao = Number(data.HuBiaoQiYeZongShu)+Number(data.HuBiaoQiTaZongShu)
    if(Number(data.HuBiaoZongShu)!=sumHuBiao){
      wx.showModal({
        title:'请输入正确的户表总数',
        showCancel: false
      })
      return true
    }
    // 户表企业总数校验
    let sumHuBiaoQiYe = Number(data.HuBiaoQiYeZhiNengGeShu)+Number(data.HuBiaoQiYeRenGongGeShu)
    if(Number(data.HuBiaoQiYeZongShu)!=sumHuBiaoQiYe){
      wx.showModal({
        title:'请输入正确的户表企业总数',
        showCancel: false
      })
      return true
    }
    // 户表其他总数校验
    let sumHuBiaoQiTa = Number(data.HuBiaoQiTaZhiNengGeShu)+Number(data.HuBiaoQiTaRenGongGeShu)
    if(Number(data.HuBiaoQiTaZongShu)!=sumHuBiaoQiTa){
      wx.showModal({
        title:'请输入正确的户表其他总数',
        showCancel: false
      })
      return true
    }
    console.log('户表位置数据',data)
    // 户表安装总数校验
    let sumHuBiaoGeShuList = JSON.parse(data.HuBiaoGeShu)
    let sumHuBiaoGeShu  = 0
    sumHuBiaoGeShuList.forEach(function(item,index){
      sumHuBiaoGeShu += Number((item.value=""?0:item.value))
    })
    console.log('户表位置数据1',data.HuBiaoZongShu)
    console.log('户表位置数据2',sumHuBiaoGeShu)
    if(Number(data.HuBiaoZongShu)!=sumHuBiaoGeShu){
      wx.showModal({
        title:'户表安装数量与总数不一致',
        showCancel: false
      })
      return true
    }
    /**
     * 供水校验
     */
    // 天面总数校验
    let sumTianMian = Number(data.TianMianHunNingTu)+Number(data.TianMianBuXiuGang)
    if(Number(data.TianMianShuLiang)!=sumTianMian){
      wx.showModal({
        title:'请输入正确的天面水池总数',
        showCancel: false
      })
      return true
    }
    // 天面混凝土总数校验
    let sumTianMianHunNingTu = Number(data.TianMianHunNingTu1)+Number(data.TianMianHunNingTu2)+Number(data.TianMianHunNingTu3)
    if(Number(data.TianMianHunNingTu)!=sumTianMianHunNingTu){
      wx.showModal({
        title:'请输入正确的天面水池混凝土总数',
        showCancel: false
      })
      return true
    }
    // 天面不锈钢总数校验
    let sumTianMianBuXiuGang = Number(data.TianMianBuXiuGang1)+Number(data.TianMianBuXiuGang2)+Number(data.TianMianBuXiuGang3)
    if(Number(data.TianMianBuXiuGang)!=sumTianMianBuXiuGang){
      wx.showModal({
        title:'请输入正确的天面水池不锈钢总数',
        showCancel: false
      })
      return true
    }
    // 地下总数校验
    let sumDiXia = Number(data.DiMianHunNingTu)+Number(data.DiMianBuXiuGang)
    if(Number(data.DiMianShuLiang)!=sumDiXia){
      wx.showModal({
        title:'请输入正确的地下水池总数',
        showCancel: false
      })
      return true
    }
    // 地下混凝土总数校验
    let sumDiXiaHunNingTu = Number(data.DiMianHunNingTu1)+Number(data.DiMianHunNingTu2)+Number(data.DiMianHunNingTu3)
    if(Number(data.DiMianHunNingTu)!=sumDiXiaHunNingTu){
      wx.showModal({
        title:'请输入正确的地下水池混凝土总数',
        showCancel: false
      })
      return true
    }
    // 地下不锈钢总数校验
    let sumDiXianBuXiuGang = Number(data.DiMianBuXiuGang1)+Number(data.DiMianBuXiuGang2)+Number(data.DiMianBuXiuGang3)
    if(Number(data.DiMianBuXiuGang)!=sumDiXianBuXiuGang){
      wx.showModal({
        title:'请输入正确的地下水池不锈钢总数',
        showCancel: false
      })
      return true
    }
    // 水池总数校验
    let sumShuiChi1 = Number(data.TianMianShuLiang)+Number(data.DiMianShuLiang)
    let sumShuiChi2 = Number(data.ShuiChiQiYongShuLiang)+Number(data.ShuiChiYongShuLiang)
    if(Number(data.ShuiChiShuLaing)!=sumShuiChi1||Number(data.ShuiChiShuLaing)!=sumShuiChi2){
      wx.showModal({
        title:'水池总数=天面水池数+地下水池数，水池总数=弃用数+在用数',
        showCancel: false
      })
      return true
    }
    return false
  },
  /**
   * 分享当前页面
   */
  onShareAppMessage() {
    let _this = this;
    return {
      title: _this.data.detail.Name,
      path: `/pages/index/idnex`,
    };
  },
  bindCenggao(e) {// 层高计算
    let louceng = e.detail.value,
      desc
    if (louceng <= 7) {
      desc = '7层及以下'
    } else if (louceng > 7 && louceng <= 15) {
      desc = '8~15层'
    } else if (louceng > 15) {
      desc = '16层及以上'
    }
    this.setData({
      cenggao: desc,
      louceng:louceng
    })
  },
  bindJisuanmianji(e){// 计算面积
    let name = e.target.dataset.name
    let _this = this
    console.log(name)
    if(name =='cb'){
      this.setData({
        changbian: e.detail.value
      })
    }else if(name==='kb'){
      this.setData({
        kuanbian: e.detail.value
      })
    }
    // let c = (this.changbian==null?0:this.changbian)
    // let k = (this.kuanbian==null?0:this.kuanbian)
    // console.log('长边'+this.data.changbian)
    // console.log('宽边'+this.data.kuanbian)
    this.setData({
      mianji: _this.data.changbian*_this.data.kuanbian
    })
  },
  addLiguanzu(e){// 添加立管组
    if(this.data.liguanList.length>17){
      wx.showToast({
        title: '立管组数量不能大于18个',
        showCancel:false
      })
      return
    }
    this.data.liguanList.push({
      genshu:'',
      zuigao:'',
      zuidi:''
    })
    this.setData({
      liguanList: this.data.liguanList
    })
  },
  delLiguanzu(e){// 删除立管组
    console.log('删除立管组')
    if(this.data.liguanList.length<2){
      wx.showToast({
        title: '已经剩最后一条了',
      })
      return
    }
    this.data.liguanList.pop()
    //渲染数据
    this.setData({
      liguanList: this.data.liguanList
    });
  },
  jisuanLiGuan(e){// 根据立管组数计算
    let loucenggaodu = this.data.louceng
    if(!loucenggaodu){
      wx.showToast({
        title: '请填写楼层'
      })
      return
    }
    let list = this.data.liguanList;// 立管组数组
    let total1 = 0,//低区室外水表总数
        total2 = 0, // 低区立管总长度
        zuigaoliguan = 0// 最高立管楼层
    list.forEach(function(item,index){
      total1 = Number(total1)+Number(item.genshu)
      total2 = Number(total2)+Number((item.genshu*(item.zuigao*3+item.zuidi*3)/2).toFixed(2))
      if(item.zuigao>zuigaoliguan){
        zuigaoliguan =  Number(item.zuigao)
      }
    })
    // 楼层层数是否＞最高立管楼层
    if(this.data.louceng>zuigaoliguan){
      let a = Number((total1))/Number(zuigaoliguan*(loucenggaodu-zuigaoliguan)).toFixed(2);
      let b = Number((total2))/Number(zuigaoliguan*(loucenggaodu-zuigaoliguan)).toFixed(2);
      this.setData({
        dayu:'是',
        gaoquzongshu:a,
        gaoquchangdu:b,
        diquzongshu:total1,
        diquchangdu:total2,
        hubiaozongshu:total1+a,
        liguanchangdu:total2+b
      })
    }else {
      this.setData({
        dayu:'否',
        diquzongshu:total1,
        diquchangdu:total2,
        hubiaozongshu:total1,
        liguanchangdu:total2
      })
    }
    // console.log('立管组数据',this.data.liguanList)
    console.log('低区室外水表总数',total1)
    console.log('低区立管总长度',total2)
  },
  onInput(e){// 立管组数数据填充
    let index = e.currentTarget.dataset.index
    let name = e.currentTarget.dataset.name
    let value = parseInt(e.detail.value)
    let _target = `liguanList[${index}].${name}`
    this.setData({
      [_target]:value
    })
  },



  radioChangeGuanCai(e) {
    console.log('管材', e.detail.value)
    this.setData({
      GuanCai: e.detail.value
    })
  },
  blurHuBiao(e){
    this.setData({
      LouDongHuShu: e.detail.value
    })
  },
  blurGuanCai(e) {
    // console.log(e)
    // console.log('管材长度',e.detail.value)
    // console.log(e.target.dataset.name)
    let cval = e.detail.value
    let cname = e.target.dataset.name
    let list = this.data.GuanCaiChangDu
    let res = false;
    list.forEach(function (item, i) {
      if (item.name == cname) {
        item.value = cval
        res = true
      }
    })
    if (!res) {
      list.push({
        name: cname,
        value: cval
      })
    }
    this.setData({
      GuanCaiChangDu: list
    })
  },
  radioChangeChaoBiao(e) {
    this.setData({
      ChaoBiaoDaoHu: e.detail.value
    })
  },
  radioChangeDongBiao(e) {
    this.setData({
      DongBiaoWeiZhi: e.detail.value
    })
    console.log('栋表位置', e.detail.value)
  },
  radioChangeDongBiaoShiNei(e) {
    this.setData({
      DongBiaoShiNei: e.detail.value
    })
    console.log('栋表室内', e.detail.value)
  },
  radioChangeDongBiaoShiWai(e) {
    this.setData({
      DongBiaoShiWai: e.detail.value
    })
    console.log('栋表室外', e.detail.value)
  },
  radioChangeHuBiao(e) {
    this.setData({
      HuBiaoWeiZhi: e.detail.value
    })
    console.log('户表位置', e.detail.value)
  },
  // 户表长度
  blurHuBiao(e) {
    let cval = e.detail.value
    let cname = e.target.dataset.name
    let list = this.data.HuBiaoGeShu
    let res = false;
    list.forEach(function (item, i) {
      if (item.name == cname) {
        item.value = cval
        res = true
      }
    })
    if (!res) {
      list.push({
        name: cname,
        value: cval
      })
    }
    this.setData({
      HuBiaoGeShu: list
    })
    console.log("户表个数", this.data.HuBiaoGeShu)
  },
  radioChangeShuiChi(e) {
    this.setData({
      ShuiChiYong: e.detail.value
    })
    console.log('水池用', e.detail.value)
    let disableQingXi;
    if(e.detail.value.indexOf("在用")>-1){
      disableQingXi = false
    }else{
      disableQingXi = true
    }
    this.setData({
      disableQingXiFangShi: disableQingXi
    })
  },
  radioChangeShuiChiZhong(e) {
    this.setData({
      ShuiChiZhong: e.detail.value
    })
    console.log('水池中', e.detail.value)
  },
  // 水池中
  bindShuiChiZhong(e) {
    let cval = e.detail.value
    let cname = e.target.dataset.name
    let list = this.data.ShuiChiZhongGeShu
    let res = false;
    list.forEach(function (item, i) {
      if (item.name == cname) {
        item.value = cval
        res = true
      }
    })
    if (!res) {
      list.push({
        name: cname,
        value: cval
      })
    }
    this.setData({
      ShuiChiZhongGeShu: list
    })
    console.log("水池中个数", list)
  },
  radioChangeGongShui(e) {
    this.setData({
      GongShuiFangShi: e.detail.value
    })
    console.log('供水方式', e.detail.value)
  },
  radioChangeQingXi(e) {
    this.setData({
      QingXiFangShi: e.detail.value
    })
    console.log('清洗方式', e.detail.value)
  },
  radioChangeShuiZhi(e) {
    this.setData({
      ShuiZhiJianCeBaoGao: e.detail.value
    })
    console.log('水质报告', e.detail.value)
  },
  radioChangeGuanli(e) {
    this.setData({
      GuanLiRenYuan: e.detail.value
    })
    console.log('管理人员', e.detail.value)
  },
  bindDateChange(e) { //填表时间
    this.setData({
      TianBiaoRiQi: e.detail.value
    })
  },
  radioChange(e) {
    let _this = this
    if (e.target.dataset.name) {
      let data = {}
      data[e.target.dataset.name] = e.detail.value
      _this.setData(data)
    }
  },
  shanchu(e) {
    //  e.target.name
    let _this = this
    console.log(e)
    let arr = []
    arr = arr.concat(_this.data[e.target.dataset.name])
    arr.splice(e.target.dataset.index, 1)
    this.setData(_this.setKeyAndValue(e.target.dataset.name, arr))
  },
  setKeyAndValue(key, value) {
    var obj = {};
    console.log(key)
    obj[key] = value
    console.log(obj)
    return obj
  },
  searchQingkong(e) {
    let _this = this;
    App._get('GetQingXiJiGou', {
      name: e.detail.value
    }, (res) => {
      console.log(res)
      if (res.length === 0) {
        res = [{
          Name: '暂无数据'
        }]
      }
      _this.setData({
        qingkongList: res
      })
    })
  },
  selectQingkong(e) {
    this.setData({
      qingkongList: [],
      ErGongSheShiQingXiJiGou: e.currentTarget.dataset.name
    })
  },
  bindXianChangZhaoPian() {
    let _this = this
    var XianChangZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.XianChangZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            XianChangZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  bindGongZuoZhaoPian() {
    let _this = this
    var GongZuoZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.GongZuoZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            GongZuoZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  bindWenTiZhaoPian() {
    let _this = this
    var WenTiZhaoPianList = []
    wx.chooseMedia({
      count: 9,
      mediaType: ['image', 'video'],
      sourceType: ['album', 'camera'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        let arr = [];
        _this.setData({
          tuResult: false
        })
        for (let i in res.tempFiles) {
          let promise = new Promise((rel, rej) => {
            App.uploaFile('/api/UpLoadProcess', res.tempFiles[i].tempFilePath, (res2) => {
              rel(siteinfo.siteroot + res2)
            })
          })
          arr.push(promise)
        }
        Promise.all(arr).then((result) => {
          console.log(result, '图片上传完成')
          let arrList = []
          arrList = arrList.concat(_this.data.WenTiZhaoPian)
          arrList.push.apply(arrList, result)
          _this.setData({
            WenTiZhaoPian: arrList,
            tuResult: true
          })
        })
      }
    })
  },
  shanchu(e) {
    //  e.target.name
    let _this = this
    console.log(e)
    let arr = []
    arr = arr.concat(_this.data[e.target.dataset.name])
    arr.splice(e.target.dataset.index, 1)
    this.setData(_this.setKeyAndValue(e.target.dataset.name, arr))
  },
  setKeyAndValue(key, value) {
    var obj = {};
    console.log(key)
    obj[key] = value
    console.log(obj)
    return obj
  },
  /**
   * 下拉刷新
   */
  onPullDownRefresh: function () {
    // 获取首页数据
    wx.stopPullDownRefresh();
  },
  /**
   * 滚动到底部
   */
  goBottom() {
    var obj = wx.createSelectorQuery();
    obj.selectAll('.container').boundingClientRect(function (rect) {
      wx.pageScrollTo({
        scrollTop: rect[0].height,
        duration: 300
      });
    })
    obj.exec();
  },
  onUnload(event){ //多层级跳转之后，监听左上角返回事件，直接退回到index
    console.log(event)
    // wx.switchTab({
    //   url: '/pages/index/index'
    // })
  },
});